package com.ruoyi.common.config.thread;

import lombok.extern.slf4j.Slf4j;

/**
 * 线程配置 抽象类
 * @author lilong
 */
@Slf4j
public abstract class AbstractWork implements Runnable {
    /**
     * 任务描述
     */
    private String workDescription;

    public AbstractWork(String workDescription) {
        this.workDescription = workDescription;
    }

    @Override
    public void run() {
        String threadName = Thread.currentThread().getName();
        try {
            log.info(threadName+"-"+workDescription+"-开始执行");
            process();
            log.info(threadName+"-"+workDescription+"-结束执行");
        }catch (Exception e){
            log.error(threadName+"-"+workDescription+"-执行异常,{}",e);
        }
    }

    /**
     * 业务逻辑处理 交由子类实现
     */
    public abstract void process ();

    public void setProperties (String workDescription)  {
        this.workDescription = workDescription;
    }

    public String getWorkDescription() {
        return workDescription;
    }
}
